/**
 * create by young (young2f@outlook.com) on 2020/12/4
 */
'use strict';
const model = require('../base/modelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    projectType: {
      type: 'string', _type: 'select', title: '项目类型', enableArea: [
        'table', 'detail', 'input', 'search'
      ],
      options: [
        '工程',
        '物资',
        '运营',
        '技术服务'
      ]
    },
    projectName: {
      type: 'string', _type: 'string', title: '项目名称', enableArea: [
        'table', 'detail', 'input', 'search'
      ],
    },
    division: {
      type: 'string', _type: 'select', title: '销售公司', enableArea: [
        'table', 'detail', 'input', 'search'
      ],
      options: [
        '镇江新蓝化工科技有限公司',
        '句容经济开发区生涌化工原料经营部',
        '江苏迈蔚环境科技有限公司',
        '江苏景开环境工程有限公司',
        '南京开广化工有限公司',
        '句容安澜环保材料有限公司',
        '阿迈斯工业产品(苏州)有限公司',
      ]
    },
    customer: {
      type: 'string', _type: 'string', title: '客户', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    customerCode: {
      type: 'string', _type: 'string', title: '客户编码', enableArea: [ 'search' ]
    },

    address: {
      type: 'string', _type: 'string', title: '地址', enableArea: [
        'detail', 'input', 'search'
      ],
    },
    contacts: {
      type: 'string', _type: 'string', title: '联系人', enableArea: [
        'detail', 'table', 'search'
      ],
    },
    contactsPhone: {
      type: 'string', _type: 'string', title: '联系人电话', enableArea: [
        'detail', 'table', 'search'
      ],
    },
    prods: {
      type: 'array', _type: 'array', title: '商品列表', enableArea: [ 'input', ],
      prodName: { type: 'string', _type: 'string', title: '商品品名', enableArea: [ 'search' ] },
      prodCode: { type: 'string', _type: 'string', title: '商品编号', enableArea: [ 'search' ] },
      count: { type: 'string', _type: 'number', title: '商品重量（KG)', enableArea: [ 'search' ] },
      price: { type: 'string', _type: 'number', title: '商品单价', enableArea: [ 'search' ] },
      label: { type: 'string', _type: 'string', title: '商品标签', enableArea: [ 'search' ] },
      pkg: { type: 'string', _type: 'string', title: '商品包装', enableArea: [ 'search' ] },
      pkgFee: { type: 'string', _type: 'number', title: '商品包装费用', enableArea: [ 'search' ] },
      laborFee: { type: 'string', _type: 'number', title: '商品劳务费用', enableArea: [ 'search' ] },
      taxDeductionPointForLaborCosts: {
        type: 'string',
        _type: 'number',
        title: '商品劳务扣税点',
        enableArea: [ 'search' ]
      },
      deliverWay: {
        type: 'string', _type: 'select', title: '商品发货方式', enableArea: [ 'search' ], options: [
          '厂家直发',
          '仓库物流',
          '仓库自送',
          '客户自提',
        ]
      },

      materials: {
        material: { type: 'string', _type: 'string', title: '原料名称', enableArea: [ 'search' ] },
        materialCode: { type: 'string', _type: 'string', title: '原料编号', enableArea: [ 'search' ] },
        materialCount: { type: 'string', _type: 'number', title: '原料数量', enableArea: [ 'search' ] },
        materialContent: { type: 'string', _type: 'string', title: '原料含量', enableArea: [ 'search' ] },
        subcategory: { type: 'string', _type: 'string', title: '原料小类', enableArea: [ 'search' ] },
        cost: { type: 'string', _type: 'number', title: '原料成本', enableArea: [ 'search' ] },
      },
      ///
      pkgs: {
        material: { type: 'string', _type: 'string', title: '原料名称', enableArea: [ 'search' ] },
        materialCode: { type: 'string', _type: 'string', title: '原料编号', enableArea: [ 'search' ] },
        materialCount: { type: 'string', _type: 'number', title: '原料数量', enableArea: [ 'search' ] },
        materialContent: { type: 'string', _type: 'string', title: '原料含量', enableArea: [ 'search' ] },
        subcategory: { type: 'string', _type: 'string', title: '原料小类', enableArea: [ 'search' ] },
        cost: { type: 'string', _type: 'number', title: '原料成本', enableArea: [ 'search' ] },
      }
    },

    count: {
      type: 'number', _type: 'number', title: '重量（KG)', enableArea: [
        'table', 'input',
        'detail',
      ], default: 0
    },
    paymentWay: {
      type: 'string', _type: 'string', title: '结款方式', enableArea: [
        'table', 'detail', 'input', 'search'
      ],
    },
    salesman: {
      type: 'string', _type: 'string', title: '业务员', enableArea: [
        'table', 'detail', 'input', 'search', 'search'
      ],
    },
    needInvoice: {
      type: 'string', _type: 'select', title: '是否需要开票', enableArea: [],
      options: [
        '需要开票',
        '不需要开票',
      ]
    },
    amount: {
      type: 'number', _type: 'number', title: '金额', enableArea: [
        'table', 'detail', 'search'
      ], default: 0
    },
    label: {
      type: 'string', _type: 'string', title: '标签', enableArea: [
        'input',
      ],
    },
    pkg: {
      type: 'string', _type: 'string', title: '包装', enableArea: [
        'input',
      ],
    },
    packageWay: {
      type: 'string', _type: 'string', title: '打包方式', enableArea: [
        'table', 'detail', 'input', 'search'
      ],
    },

    deliverWay: {
      type: 'string', _type: 'select', title: '发货方式', enableArea: [
        'detail', 'input', 'search'
      ],
      options: [
        '厂家直发',
        '仓库物流',
        '仓库自送',
        '客户自提',
      ]
    },
    deliverRequire: {
      type: 'string', _type: 'string', title: '发货要求', enableArea: [
        'input', 'search'
      ],
    },
    deliverChannel: {
      type: 'string', _type: 'string', title: '送货渠道', enableArea: [
        'input',
      ],
    },
    // deliverDate: {
    //   type: 'date', _type: 'date', title: '发货日期', enableArea: [
    //     'detail', 'input', 'search'
    //   ],
    // },
    outboundAmount: {
      type: 'number', _type: 'number', title: '出库金额', disabled: true, enableArea: [
        'detail', 'table'
      ], default: 0
    },
    outboundCount: {
      type: 'number', _type: 'number', title: '出库数量', disabled: true, enableArea: [
        'detail', 'table'
      ], default: 0
    },
    outboundDate: {
      type: 'date', _type: 'date', title: '出库时间', disabled: true, enableArea: [],
    },

    mainCost: {
      type: 'number',
      _type: 'number',
      title: '主成本',
      enableArea: [ 'input', 'detail', 'search', 'table' ]
    },
    auxiliaryMaterialFee: {
      type: 'number',
      _type: 'number',
      title: '辅料成本',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    mgrFee: {
      type: 'number', _type: 'number', title: '管理成本', enableArea: [
        'input', 'detail', 'search'
      ], default: 0
    },
    shippingFee: {
      type: 'number',
      _type: 'number',
      title: '运费',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    returnShippingFee: {
      type: 'number',
      _type: 'number',
      title: '租用返回运费',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    unloadFee: {
      type: 'number',
      _type: 'number',
      title: '卸货费用',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    // pkgFee: {
    //   type: 'number',
    //   _type: 'input',
    //   title: '包装费用',
    //   enableArea: [ 'input', 'detail', ]
    // },
    tray: {
      type: 'number',
      _type: 'number',
      title: '打包费用',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    // taxDeductionPointForLaborCosts: {
    //   type: 'number',
    //   _type: 'input',
    //   title: '劳务费用扣税点',
    //   enableArea: [ 'input', 'detail', ]
    // },
    // commission: {
    //   type: 'number',
    //   _type: 'input',
    //   title: '佣金',
    //   enableArea: [ 'input', 'detail', ]
    // },
    publicFee: {
      type: 'number',
      _type: 'number',
      title: '公关费用',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    laborFeeTotal: {
      type: 'number',
      _type: 'input',
      title: '劳务费用',
      enableArea: [ 'input', 'detail', ]
    },
    laborRatio: {
      type: 'number',
      _type: 'number',
      title: '劳务比例',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    taxRate: {
      type: 'string',
      _type: 'select',
      title: '税率',
      enableArea: [ 'table', 'detail', 'search' ],
      options: [
        '13%', '9%', '6%', '3%', '1%', '0%'
      ]
    },
    tax: {
      type: 'number', _type: 'code', title: '税额', enableArea: [
        'detail'
      ], default: 0
    },
    valueAddedTax: {
      type: 'number',
      _type: 'number',
      title: '增值税',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    addedTax: {
      type: 'number',
      _type: 'number',
      title: '附加税',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    incomeTax: {
      type: 'number', _type: 'number',
      title: '所得税',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    stampDuty: {
      type: 'number', _type: 'number',
      title: '印花税',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    profit: {
      type: 'number', _type: 'number',
      title: '利润',
      enableArea: [ 'input', 'detail', 'search' ]
    },
    // invoiceTime: {
    //   type: 'date', _type: 'date', title: '开票时间', enableArea: [
    //     'input', 'detail',  'search'
    //   ],
    // },

    invoiceType: {
      type: 'string', _type: 'select', title: '发票类型', enableArea: [
        'input', 'detail', 'search'
      ],
      options: [
        '专票',
        '普票',
        '不开票',
      ]
    },
    reviewStatus: {
      type: 'string', _type: 'string', title: '审核状态', disabled: true, enableArea: [
        'table', 'detail', 'search'
      ], default: '待审核'
    },

    outboundCodes: {
      type: 'array', _type: 'array', title: '出库单编码列表', disabled: true, enableArea: []
    },

    memo: {
      type: 'string', _type: 'string', title: '备注', enableArea: [ 'detail', 'search'

      ],
    },
    fileList: {
      type: 'array', _type: 'array', title: '合同', enableArea: []
    },
    qsdFileList: {
      type: 'array', _type: 'array', title: '签收单', enableArea: []
    },
    fpFileList: {
      type: 'array', _type: 'array', title: '发票', enableArea: []
    },
    pdfFileList: {
      type: 'array', _type: 'array', title: 'PDF', enableArea: []
    },
    createType: {
      type: 'string', _type: 'string', title: '创建类型', enableArea: [],
    },
    isEnabled: {
      type: 'boolean', title: '是否删除', enableArea: [],
    },

    rentStartDate: { type: Date, _type: 'date', title: '租用开始时间', enableArea: [ 'table', 'input', 'detail', ], },
    rentEndDate: { type: Date, _type: 'date', title: '租用结束时间', enableArea: [ 'table', 'input', 'detail', ], },
    rentReturnDate: { type: Date, _type: 'date', title: '实际回收时间', enableArea: [ 'table', 'input', 'detail', ], },

    // mainCostReviewStatus: {
    //   type: 'string',
    //   _type: 'string',
    //   title: '主成本审核状态',
    //   enableArea: ['detail'],
    //   default: '待审核'
    // },
    // auxMaterialReviewStatus: {
    //   type: 'string',
    //   _type: 'string',
    //   title: '辅材审核状态',
    //   enableArea: ['detail'],
    //   default: '待审核'
    // },
    // shippingFeeReviewStatus: {
    //   type: 'string',
    //   _type: 'string',
    //   title: '运费审核状态',
    //   enableArea: ['detail'],
    //   default: '待审核'
    // },
    // publicFeeReviewStatus: {
    //   type: 'string',
    //   _type: 'string',
    //   title: '公关费审核状态',
    //   enableArea: ['detail'],
    //   default: '待审核'
    // },
    // loadFeeReviewStatus: {
    //   type: 'string',
    //   _type: 'string',
    //   title: '卸货费审核状态',
    //   enableArea: ['detail'],
    //   default: '待审核'
    // },
    // laborFeeReviewStatus: {
    //   type: 'string',
    //   _type: 'string',
    //   title: '劳务费审核状态',
    //   enableArea: ['detail'],
    //   default: '待审核'
    // },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  _schema.index({ 'code': 1 });
  return connect.model('SalesOrder', _schema);
};
/**
 current: { type: 'number' },
 voltage: { type: 'number' },
 activePower: { type: 'number' },
 positiveActiveEnergy: { type: 'number' },
 ReverseActiveEnergy: { type: 'number' },
 currentA: { type: 'number' },
 currentB: { type: 'number' },
 currentC: { type: 'number' },
 voltageA: { type: 'number' },
 voltageB: { type: 'number' },
 voltageC: { type: 'number' },
 */
